package base.多线程.扩展JUC.温度传感器类;

import java.util.concurrent.TimeUnit;

public class ReadTemperatureThread implements Runnable{

    private TemperatureSensor tem;

    public ReadTemperatureThread(TemperatureSensor tem) {
        this.tem = tem;
    }

    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        while (true){
            System.out.println(name+"：当前温度>>>"+tem.getTemperture()+"℃");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
